package hello;

import static hello.ActiveMQConfig.ORDER_TOPIC;

import java.math.BigDecimal;
import java.time.LocalDateTime;

import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;



@Controller
public class GreetingController {

	private static Logger log = LoggerFactory.getLogger(GreetingController.class);
	 
    @Autowired
    private OrderSender orderSender;

    
    
    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        Thread.sleep(2); // simulated delay
        Order order = new Order("me", message.getName(), new BigDecimal(1), LocalDateTime.now());
        orderSender.sendTopic(order);
        return new Greeting("Hello, " + message.getName() + "!");
    }
    
   

}
